// 快速排序算法
// 核心思想是通过分治策略将数组划分为更小的子数组，递归排序后合并结果


function quickSort(arr) {
  if (arr.length <= 1) {
    return arr
  }

  const pointIndex = Math.floor(arr.length / 2)
  point = arr[pointIndex]

  let left = []
  let right = []
  let equal = []

  for (const num of arr) {
    if (num < point) {
      left.push(num)
    } else if (num > point) {
      right.push(num)
    } else {
      equal.push(num)
    }
  }

  return [...quickSort(left), ...equal, ...quickSort(right)]
}